function DailyFaultMan() {
	var divId = "affectObjDiv";
	var currentItem = "";
	var queryGap = undefined;
	var util = new DailyUtil();
	var mans = {
			run : new RunMan(),
			alarm : new AlarmMan(),
			defect : new DefectMan(),
			overhaul : new OverhaulMan(),
			risk : new RiskMan(),
			newequipment : new NewEquipmentMan(),
			special : new SpecialReportMan(),
			historyFault:new HistoryFaultFeedBackMan()
	};
	var iconTypes = {
			fault : 'run',
			history : 'run',
			interrupt : 'alarm',
			double : 'alarm',
			frequently : 'alarm',
			defect : 'defect',
			todo : 'overhaul',
			doing : 'overhaul',
			done : 'overhaul',
			overhaulDetail : 'overhaul'
	};

	var start = '';
	var end = '';
	getDefaultDays();
	this.getStart = function() {
		return start;
	};
	this.getEnd = function() {
		return end;
	};
	this.show = function(item) {
		currentItem = item;
		clearAll();
		mans[currentItem].show();
	};
	this.zoom = function(level){
		if(mans[currentItem].zoom){
			mans[currentItem].zoom(level);
		}
	};
	this.clear = function(){
		$('#' + divId).css('display', 'none');
		if(mans[currentItem].clear){
			mans[currentItem].clear();
		}
	};
	this.openPop = function(group, type, value) {
		mans[group].openPop(type, value);
	};
	this.openDialog = function(group, type, value) {
		mans[group].openDialog(type, value);
	};
	this.query = function() {
		var sval = $('#start').val();
		var eval = $('#end').val();
		var s = new Date(sval);
		var e = new Date(eval);
		// 将空的和不对的补齐
		if(!sval || s.toString() == 'Invalid Date'){
			$('.ice-warning-start').val(start);
			s = new Date(start);
		}else{
			start = sval;
		}
		if(!eval || e.toString() == 'Invalid Date'){
			$('.ice-warning-end').val(en);
			e = new Date(end);
		}else{
			end = eval;
		}
		if (s && e) {
			var gap = e.getTime() - s.getTime();
			if (!queryGap) {
				$.ajaxSettings.async = false;
				$.getJSON("/rest/getDailyReportQueryMaxDay", function(result) {
					queryGap = Number(result.day);
				});
				$.ajaxSettings.async = true;
			}
			if (gap > queryGap * 24 * 3600 * 1000) {
				$("#dailyQueryError").html(localeTitle.ChaXunShiJianBuChaoGuo + queryGap +localeTitle.Tian+ "！");
				$("#dailyQueryError").collapse('show');
			} else if (gap < 0) {
				$("#dailyQueryError").html(localeTitle.ChaXunKaiShiShiJianBuChaoGuoJieShuShiJian + "！");
				$("#dailyQueryError").collapse('show');
			} else {
				$("#dailyQueryError").collapse('hide');
				mans[currentItem].query();
			}
		} else {
			$("#dailyQueryError").html(localeTitle.ChaXunShiJianBuBiaoZhun+"！");
			$("#dailyQueryError").collapse('show');
		}
	};
	this.dateMinus = function() {
// var str = $('#start').val().substring(0,10);
        var str = $('#start').val();
		var ymd = str.split('-');
		var d = new Date(str);
		d.setFullYear(ymd[0], ymd[1] - 1, ymd[2] - 1);
		var m = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : '0' + (d.getMonth() + 1);
        var day = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
// var dStr = d.getFullYear() + "-" + m + "-" + day+" 00:00:00";
        var dStr = d.getFullYear() + "-" + m + "-" + day;
		$('#start').val(dStr);
	};
	this.changeDate = function(end,start){
		var s = new Date();
		var e = new Date();
		s.setDate(s.getDate() + start);
		s.setHours(0, 0, 0, 0);
		e.setDate(e.getDate() + end);
		e.setHours(23, 59, 59, 999);
		start = util.getDayTimeStr(s.getTime());
		end = util.getDayTimeStr(e.getTime());
		$('#start').val(start);
		$('#end').val(end);
		this.query();
	};
	function getDefaultDays() {
		var s = new Date();
		var e = new Date();
		if (s.getDay() == 1) {
			s.setDate(s.getDate() - 3);
		} else {
			s.setDate(s.getDate() - 1);
		}
		s.setHours(0, 0, 0, 0);
		e.setDate(e.getDate() - 1);
		e.setHours(23, 59, 59, 999);
		start = util.getDayTimeStr(s.getTime());
		end = util.getDayTimeStr(e.getTime());
		// 演示方便暂时添加
		// start='2017-09-26';
		// end='2017-09-27';
	}
	this.onPanelClick = function(type) {
		mans[iconTypes[type]].onPanelClick(type);
	};
	this.showProcessPop = function(type, value) {
		mans[iconTypes[type]].showProcessPop(type, value);
	};
	this.removeProcessPop = function(type) {
		mans[iconTypes[type]].removeProcessPop();
	};
	this.closePop = function(popId) {
		var pops = map.popups;
		for (var i = 0; i < pops.length; i++) {
			if (pops[i].id == popId) {
				map.removePopup(pops[i]);
				break;
			}
		}
	};
}
function RunMan() {
	var divId = "affectObjDiv";
	var divTitle = localeTitle.daily.GuZhangRiBao;
	var util = new DailyUtil();
	var panels = new PanelTablesUtil(divId);
	
	var isShow = false;
	
	var runs = {
			fault : []
	};
	var equipments = {
			fault : []
	};

	var processPop = undefined;

	/**
	 * 用于画红点和地图弹窗
	 */
	var mapFeature = (function(){
		var dataMap ;// map
		var data ;
		var popMap = new Map();
		var merge = new MergeGeo();
		function setData(d){
			data = d;
			merge.setData(data);
		}
		function mergeData(level){
			var group = merge.getMergeData(level);
			
			dataMap = new Map();
			for(var i in group){
				var gs = group[i].data;
				var key = gs[0].lon+","+gs[0].lat;// 去第一个点作为画点
				var value = {};
				for(var j in gs){
					var k = gs[j].etype == '线路'?gs[j].equipment:gs[j].stationName;
					var vs = value[k];
					if(!vs){
						vs = [];
						value[k] = vs;
					}
					vs.push(gs[j]);
				}
				dataMap.put(key, value);
			}
		}
		function draw(level){
			if(merge.isChange(level)){
				mergeData(level);
			}
			clear();
			// 画点
			util.markPoint(dataMap, util.getGif('fault'), 'run', 'fault');
			addFaultPops(dataMap);
		}
		// 在地图上显示"故障报告"的信息
		function addFaultPops(dataMap) {
			popMap.clear();
			dataMap.each(function(index, key, value) {
				var pop = getFaultPop(key,value);
				pop.show();
				if(detectCollision(pop,popMap)){
					pop.remove();
				}
				popMap.put(key, pop);
			});
		}
		// 检测碰撞
		function detectCollision(pop,popMap){
			var popup = pop.getPop();
			var div = popup.div;// h w
			var left = div.offsetLeft;
			var right = div.offsetLeft + div.offsetWidth;
			var top = div.offsetTop;
			var bottom = div.offsetTop + div.offsetHeight;
			var bound = [left,right,top,bottom];
			var pops = popMap.values();
			for(var i in pops){
				var p2 = pops[i];
				if(p2.isShow()){
					var d2 = p2.getPop().div;
					var b2 = [d2.offsetLeft,d2.offsetLeft + d2.offsetWidth,d2.offsetTop,d2.offsetTop + d2.offsetHeight];
					if(isInside(b2[0],b2[2],bound) || isInside(b2[1],b2[2],bound) || isInside(b2[0],b2[3],bound) || isInside(b2[1],b2[3],bound)){
						return true;
					}else if(isInside(bound[0],bound[2],b2) || isInside(bound[0],bound[3],b2) ||isInside(bound[1],bound[2],b2) ||isInside(bound[1],bound[3],b2) ){
						return true;
					}
				}
			}
			
			return false;
		}
		function isInside(x,y,bound){
			if(x >= bound[0] && x <= bound[1] && y >= bound[2] && y <= bound[3] ){
				return true;
			}
			return false;
		}
		function getFaultPop(lonlat,dataMap) {
			var ll = lonlat.split(',');
			var pop = new Popup(Number(ll[0]), Number(ll[1]));
			for(var equipment in dataMap){
				pop.setTitle(equipment);
				var value = dataMap[equipment];
				for ( var i in value) {
					var v = value[i];
					var t = util.getSecondTimeStr(v.faultTime.time?v.faultTime.time:v.faultTime);
					var clicklistener = 
						"dailyFaultMan.openDialog('run','detail','"+
						t+","+v['equipment_id']+"')";
					pop.setRowContent(FaultAlarmMan.getFaultPopRowContent(v))
					.setRowIconClickListener(clicklistener)
					.setRowSelfClickListener(clicklistener)
					.setRowSelfHoverPopupContent(FaultAlarmMan.getFaultProcessContent(v));
				}
			}
			pop.setAutoSize(true);
			pop.showCloseIcon(true);
			return pop;
		}
		function clear(){
			weatherLayer.removeAllFeatures();
			map.removeAllPopup();
		}
		function getPopup(key){
			return popMap.get(key);
		}
		return {
			setData:setData,
			show:draw,
			clear:clear,
			getPopup:getPopup,
		};
	})();
	
	this.show = function() {
		isShow = true;
		initData();
	};
	this.query = function() {
		clearAll();
		isShow = true;
		initData();
	};
	this.zoom = function(level){
		if(isShow){
			mapFeature.show(level);
		}
	};
	this.openPop = function(type, value) {
		var pop = undefined;
		if (type == "fault") {
			var lon = undefined,lat = undefined;
			for(var i in value){
				lon = value[i][0].lon;
				lat = value[i][0].lat;
				break;
			}
			pop = mapFeature.getPopup(lon+','+lat);
		}
		if (pop) {
			if (pop.isShow()) {
				pop.remove();
			} else {
				pop.show();
			}
		}
	};
	this.openDialog = function(type, value) {
		if (type == 'list') {
			var url = "/ui/map/dialog/daily/dailyFault.xhtml";
			util.openDialogWithTimeParamter(url);
		}
		if (type == 'detail') {
			value = value.split(',');
			var url = "/ui/map/protectActSvg/protectActSvg.xhtml";
			util.openDialogWithTimeParamter(url, {
				faultTime : value[0],
				lineId : value[1]
			});
		}
	};
	this.showProcessPop = function(type, id) {
		if (processPop) {
			map.removePopup(processPop);
		}
		if (type == 'fault') {
			addFaultProcessPop(id);
		}
	};
	this.removeProcessPop = function() {
		if (processPop) {
			map.removePopup(processPop);
		}
	};
	this.clear = function(){
		isShow = false;
	};
	function initData() {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		$.ajaxSettings.async = false;
		$.getJSON("/rest/fault/getFaultByStartAndEnd/" + start + "/" + end, function(result) {
			result.sort(sortTime);
			runs.fault = result;
			var res = util.loadMapAndEquip(runs.fault, [ 'lon', 'lat'], {
				'equipmentId' : 'equipment_id',
				'equipmentType' : 'etype',
				'lon':'lon',
				'lat':'lat'
			}, 'equipment');
			equipments.fault = res.equipment;
		});
		$.getJSON("/rest/fault/getFaultHisRebackByStartAndEnd/" + start + "/" + end, function(result) {
			runs.history = result;
		});
		$.ajaxSettings.async = true;
		show();
	}
	function sortTime(obj1, obj2) {
		var d1 = DateUtil.getDate(obj1.faultTime);
		var d2 = DateUtil.getDate(obj2.faultTime);
		if (d1.getTime() > d2.getTime()) {
			return 1;
		} else {
			return -1;
		}
	}
	function show() {
		showDiv();
		map.removeAllPopup();
		
		markLines(runs.fault);
		
		// 每次放缩的时候，需要
		mapFeature.setData(runs.fault);
		mapFeature.show(currentZoomLevel);
	}
	function markLines(data){
		for(var i in data){
			var d = data[i];
		// searchSelectObj(d.mapSearchName,false,true,d.mapSearchId);
			for(var i =0 ; i < lines500.length;i++){
				var obj = lines500[i];
				if(obj.lineName.indexOf(d.mapSearchName) > -1 ||( d.mapSearchId != null && d.mapSearchId+"" === obj.lineId+"")){
					draw_acline_one(lines500[i]);
				}
			}
		}
	}
	function showDiv() {
		panels = new PanelTablesUtil(divId);
		panels.setTitle("<span>" + divTitle + "  <small style=\"color:#A6A6A6\">" + localeTitle.daily.BaoHuRiBao
				+ "</small></span>");
		panels.setInfo(util.getQueryDiv());
		addFaultDiv(panels);
		panels.show(); 
		for ( var i in runs) {
			length += runs[i].length;
		}
		if (length > 0) {
			panels.setDangerBox();
		} else {
			panels.setSuccessBox();
		}
		util.setQueryTimePicker();
	}
	function addFaultDiv(panels) {
		var expand = true;
		// var subTitle = "<span class='pull-right' style='color:gray;'
		// onclick='dailyFaultMan.openDialog(\"run\",\"history\")'>往期故障反馈</span>";
		var subTitle = '';
		var detail = "<span class='pull-right' style='color:gray;' onclick='dailyFaultMan.openDialog(\"run\",\"list\")'>"
			+ localeTitle.mingXi + "</span>";
		panels.setInfo("<div style='margin:5px;font-weight:bold;'>"+localeTitle.fault.ZhuWangGongFaSheng+"<span class='margin' style='font-size:larger'>"+runs.fault.length+"</span>"+localeTitle.fault.QiTiaoZhaShiJian+"</div>");
		if (runs.fault.length > 0) {
			var dataset = util.getDataset(runs.fault, [ 'equipment', {
				value : "faultTime",
				type : "secondTimeStr"
			}, 'faultType','mapSearchId','mapSearchName']);
			var title = localeTitle.daily.BaoHuRiBao
			+ "<span title='故障个数' onclick='dailyFaultMan.openDialog(\"run\",\"list\")' class='badge bg-red pull-right'>"
			+ dataset.length + "</span>";
			title += subTitle + detail;
			var tableDiv = panels.drawCollapseTable("dailyFaultTable", title, expand);
			var columns = [localeTitle.fault.GuZhangSheBei,localeTitle.fault.GuZhangShiJian , localeTitle.fault.GuZhangLeiXing,'变电站'];
			var option = util.getFaultTableOption();
			option.scrollY = getTableY();
			if(option.scrollY < 10){
				option.scrollY = 10;
			}
			var table = new MyTable(tableDiv, columns, option);
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					searchSelectObj(data[4],true,false,data[3]);
				}
			});
			table.onRowDbClick(function(data,event, index) {
				var v = runs.fault[index];
				var t = util.getSecondTimeStr(v.faultTime.time?v.faultTime.time:v.faultTime);
				dailyFaultMan.openDialog('run','detail',t+','+v['equipment_id']);
			});
		} else {
			var title = localeTitle.daily.BaoHuRiBao;
			title += subTitle + detail;
			var ele = panels.getCollapsePanelEle("dailyFaultParent", title, expand);
			ele.append(PanelTablesUtil.getSmileInfo(localeTitle.fault.WuGuZhangFaSheng));
		}
	}

	function getTableY(){
		var mapH = window.map.size.h;
		var top = 70+40+64+33+43+3+44+20;// 70面板距顶部距离40标题64搜索区33汉字区43分区标题3表格边界44表格列名15冗余
		return mapH-top;
	}
}
function AlarmMan() {
	var divId = "affectObjDiv";
	var divTitle = localeTitle.daily.TongDaoJianShi;
	var interruptTitle = localeTitle.daily.BaoHuTongDaoZhongDuan;
	var doubleTitle = localeTitle.daily.ShuangTongDaoZhongDuan;
	var frequentlyTitle = localeTitle.daily.BaoHuTongDaoPinFanZhongDuan;
	var util = new DailyUtil();
	var panels = new PanelTablesUtil(divId);
	var currentPop = undefined;
	var alarms = {
			interrupt : [],
			double : [],
			frequently : []
	};
	var lonlatMaps = {
			interrupt : new Map(),
			double : new Map(),
			frequently : new Map()
	};
	var equipments = {
			interrupt : [],
			double : [],
			frequently : []
	};
	var popMap = {
			interrupt : new Map(),
			double : new Map(),
			frequently : new Map()
	};
	var currentType = 'interrupt';
	var processPop = undefined;
	this.show = function() {
		initData();
	};
	this.query = function() {
		clearAll();
		initData();
	};
	this.onPanelClick = function(type) {
		if (currentType != type) {
			selectedLayer.removeAllFeatures();
			weatherLayer.removeAllFeatures();
			searchObjLayer.removeAllFeatures();
			map.removeAllPopup();
			currentType = type;
			util.markPoint(lonlatMaps[currentType], util.getGif(currentType), 'alarm', currentType);
			util.markLines(equipments[currentType]);
			if (currentType != 'interrupt') {
				map.removeAllPopup();
			}
		}
	};
	this.openPop = function(type, value) {
		var pop = undefined;
		if (type == "interrupt") {
			pop = popMap.interrupt.get(value['stationId']);
		}
		if (pop) {
			if (pop.isShow()) {
				pop.remove();
				currentPop = undefined;
			} else {
				if (currentPop) {
					currentPop.remove();
				}
				pop.show();
				currentPop = pop;
			}
		}
	};
	this.showProcessPop = function(type, id) {
		if (processPop) {
			map.removePopup(processPop);
		}
	};
	this.removeProcessPop = function() {
		if (processPop) {
			map.removePopup(processPop);
		}
	};
	this.openDialog = function(type, value) {
		if (type == 'interrupt') {
			var url = '/ui/map/dialog/daily/dailyInterruptAlarm.xhtml';
			util.openDialogWithTimeParamter(url, {
				stationId : value
			});
		} else if (type == 'interruptList') {
			var url = "/ui/map/dialog/daily/dailyInterruptAlarm.xhtml";
			util.openDialogWithTimeParamter(url);
		} else if (type == 'doubleList') {
			var url = "/ui/map/dialog/daily/dailyDoubleChannelInterruptAlarm.xhtml";
			util.openDialogWithTimeParamter(url);
		} else if (type == 'frequentlyList') {
			var url = "/ui/map/dialog/daily/dailyFrequentlyInterruptAlarm.xhtml";
			util.openDialogWithTimeParamter(url);
		}
	};
	function initData() {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		$.ajaxSettings.async = false;
		$.getJSON("/rest/protectAlarm/getMapProtectInterruptAlarm/" + start + "/" + end, function(result) {
			alarms.interrupt = result;
			alarms.interrupt.sort(sortAlarm);
			var res = util.loadMapAndEquip(alarms.interrupt, [ 'lon', 'lat', 'stationName' ], {
				'stationId' : 'stationId'
			}, 'stationName');
			lonlatMaps.interrupt = res.map;
			equipments.interrupt = res.equipment;
		});
		$.getJSON("/rest/protectAlarm/getMapFrequentProtectInterruptAlarm/" + start + "/" + end, function(result) {
			alarms.frequently = result;
			/*
			 * var res = util.loadMapAndEquip(alarms.interrupt, [ 'lon',
			 * 'lat','stationName' ], {'stationId' : 'stationId'},
			 * 'stationName'); lonlatMaps.interrupt = res.map;
			 * equipments.interrupt = res.equipment;
			 */
		});
		$.getJSON("/rest/protectAlarm/getMapFrequentDoubleChannelAlarm/" + start + "/" + end, function(result) {
			alarms.double = result;
			/*
			 * var res = util.loadMapAndEquip(alarms.interrupt, [ 'lon',
			 * 'lat','stationName' ], {'stationId' : 'stationId'},
			 * 'stationName'); lonlatMaps.interrupt = res.map;
			 * equipments.interrupt = res.equipment;
			 */
		});
		$.ajaxSettings.async = true;
		show();
	}
	function sortAlarm(obj1, obj2) {
		var t1 = obj1.eventStart ? obj1.eventStart : 0;
		t1 = t1.time ? t1.time : t1;
		var t2 = obj2.eventStart ? obj2.eventStart : 0;
		t2 = t2.time ? t2.time : t2;
		return t2 - t1;
	}
	function show() {
		showDiv();
		showPoints();
		addInterruptPops();
	}
	function showPoints() {
		if (lonlatMaps[currentType]) {
			util.markPoint(lonlatMaps[currentType], util.getGif(currentType), 'alarm', currentType);
		}
	}
	function showDiv() {
		panels = new PanelTablesUtil(divId);
		panels.setTitle("<span>" + divTitle + "  <small style=\"color:#A6A6A6\">" + localeTitle.daily.BaoHuRiBao
				+ "</small></span>");
		panels.setInfo(util.getQueryDiv());
		addInterruptDiv(panels);
		addFrequentlyDiv(panels);
		addDoubleDiv(panels);
		panels.show();
		for ( var i in alarms) {
			length += alarms[i].length;
		}
		if (length > 0) {
			panels.setDangerBox();
		} else {
			panels.setSuccessBox();
		}
		util.setQueryTimePicker();
	}

	// 在地图上显示"通信中断异常"的信息
	function addInterruptPops() {
		var interruptmap = new Map();
		for ( var i in alarms.interrupt) {
			var r = alarms.interrupt[i];
			var ds = interruptmap.get(r['stationId']);
			if (!ds) {
				ds = [];
				interruptmap.put(r['stationId'], ds);
			}
			ds.push(r);
		}
		popMap.interrupt.clear();
		interruptmap.each(function(index, key, value) {
			var pop = getInterruptPop(value);
			popMap.interrupt.put(key, pop);
			// pop.show();
		});
	}
	function getInterruptPop(value) {
		var station = value[0];
		var clicklistener = "dailyFaultMan.openDialog('alarm','interrupt','" + station['stationId'] + "');";
		var pop = new Popup(station.lon, station.lat);
		pop.setTitle(station['stationName']).setTitleIconClickListener(clicklistener).setTitleSelfClickListener(
				clicklistener);
		for ( var i in value) {
			var protectName = '<span style="margin-right:5px;">' + value[i]['lineName'] + ' ' + value[i]['protectType']
			+ '</span>';
			var t = value[i]['eventStart'];
			t = new Date(t.time ? t.time : t);
			var eventStart = (t.getMonth() + 1) + '月' + t.getDate() + '日  ' + t.getHours() + '时' + t.getMinutes() + '分';
			eventStart = '<span style="color:red;margin-right:5px;">' + eventStart + '</span>';
			var alarmMsg = value[i]['alarmMsg'];
			var c = protectName + eventStart + alarmMsg;
			pop.setRowContent(c).setRowClickListener(clicklistener);
		}
		pop.setAutoSize(true);
		pop.showCloseIcon(true);
		return pop;
	}
	function addInterruptDiv(panels) {
		var expand = false;
		// var expand = currentType == 'interrupt';
		var clickListener = 'dailyFaultMan.onPanelClick(\'interrupt\');';
		var openList = 'dailyFaultMan.openDialog("alarm","interruptList")';
		var title = interruptTitle;
		var sub = "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
		+ "</span>";
		if (alarms.interrupt.length > 0) {
			title += "<span title='保护通信中断个数' onclick='" + openList + "' class='badge bg-red pull-right'>"
			+ alarms.interrupt.length + "</span>";
			title += sub;
			var ele = panels.getCollapsePanelEle("dailyInterruptDiv", title, expand, clickListener);
			// pie图数据
			var counts = {
					interrupt : 0,
					other : 0
			};
			var durationTimes = {
					interrupt : 0,
					other : 0
			};
			for ( var i in alarms.interrupt) {
				var r = alarms.interrupt[i];
				if (r.channelAlarms && r.channelAlarms.length > 0) {
					counts.interrupt++;
					durationTimes.interrupt += (r.durationTime ? r.durationTime : 0);
				} else {
					counts.other++;
					durationTimes.other += (r.durationTime ? r.durationTime : 0);
				}
			}
			var time = ((durationTimes.interrupt + durationTimes.other) / 1000 / 3600).toFixed(2);
			ele.append("<span style='margin-left:15px;'>"+localeTitle.channel.BaoHuTongXiZhongDuanFaSheng+"<span style='color:red;font-size:20px;'> "
					+ alarms.interrupt.length +" </span>"+localeTitle.channel.Ci+"，"+localeTitle.channel.GongJi+"<span style='color:red;font-size:20px;'> " + time
					+ " </span>"+localeTitle.channel.XiaoShi+"</span>");
			var pieDiv = $('<div id="dailyInterruptPie" style="height:150px;width:300px;" ></div>');
			ele.append(pieDiv);
			var color1 = '#dd4b39';
			var color2 = 'cadetblue';
			var pie = echarts.init(pieDiv[0]);
			var data1 = [];
			data1.push({
				name : '通信通道中断',
				value : counts.interrupt,
				itemStyle : {
					normal : {
						color : color1
					}
				}
			});
			if (counts.other > 0) {
				data1.push({
					name : '保护通道中断',
					value : counts.other,
					label : {
						normal : {
							show : false
						},
						emphasis : {
							show : false
						}
					},
					labelLine : {
						normal : {
							show : false
						},
						emphasis : {
							show : false
						}
					},
					itemStyle : {
						normal : {
							color : color2
						}
					}
				});
			}
			var option = {
					series : [ {
						name : '通信中断次数',
						type : 'pie',
						center : [ '50%', '50%' ],
						radius : '60%',
						minAngle : 5,
						label : {
							normal : {
								formatter : '{b}\n{c}次'
							}
						},
						data : data1
					} ]
			};
			pie.setOption(option);
		} else {
			title += sub;
			var ele = panels.getCollapsePanelEle("dailyInterruptDiv", title, expand, clickListener);
			ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WuTongXinZhongDuanYiChang));
		}
	}
	function addFrequentlyDiv(panels) {
		var expand = false;
		var clickListener = 'dailyFaultMan.onPanelClick(\'frequently\');';
		var tableId = 'dailyFrequentlyTable';
		var openlist = 'dailyFaultMan.openDialog("alarm","frequentlyList")';
		var title = frequentlyTitle;
		if (alarms.frequently.length > 0) {
			title += "<span title='" + frequentlyTitle + "次数' onclick='" + openlist
			+ "' class='badge bg-red pull-right'>" + alarms.frequently.length + "</span>";
			title += "<span style='color:gray;' onclick='" + openlist + "' class='pull-right'>" + localeTitle.mingXi
			+ "</span>";
			var tablediv = panels.drawCollapseTable(tableId, title, expand, clickListener);
			var columns = [ localeTitle.channel.XianLu,localeTitle.channel.BaoHu , localeTitle.channel.PinFanCiShu];
			var opt = util.getTableOption();
			opt.orderFixed = [ [ 0, 'asc' ] ];
			var table = new MyTable(tablediv, columns, opt);
			var dataset = [];
			for ( var i in alarms.frequently) {
				var f = alarms.frequently[i];
				dataset.push([ f.lineName, f.protectType, f.alarms.length ]);
			}
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			title += "<span style='color:gray;' onclick='" + openlist + "' class='pull-right'>" + localeTitle.mingXi
			+ "</span>";
			var ele = panels.getCollapsePanelEle(tableId + "Div", title, expand, clickListener);
			ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WeiFaShengBaoHuTongDaoPinFanZhongDuan));
		}
	}
	function addDoubleDiv(panels) {
		var expand = false;
		var clickListener = 'dailyFaultMan.onPanelClick(\'double\');';
		var openList = 'dailyFaultMan.openDialog("alarm","doubleList")';
		var tableId = 'dailyDoubleTable';
		var title = doubleTitle;
		if (alarms.double.length > 0) {
			title += "<span title='" + doubleTitle + "次数' onclick='" + openList + "' class='badge bg-red pull-right'>"
			+ alarms.double.length + "</span>";
			title += "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
			+ "</span>";
			var tablediv = panels.drawCollapseTable(tableId, title, expand, clickListener);
			var columns = [ localeTitle.channel.XianLu, localeTitle.channel.BaoHu, localeTitle.channel.ShiJian ];
			var opt = util.getTableOption();
			opt.order = [ [ 0, 'asc' ], [ 1, 'asc' ] ];
			var table = new MyTable(tablediv, columns, opt);
			var dataset = [];
			for ( var i in alarms.double) {
				var f = alarms.double[i];
				dataset.push([ f.lineName, f.protectType, (f.continueMs / 60000).toFixed(2) + '分钟' ]);
			}
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			title += "<span style='color:gray;' onclick='" + openList + "' class='pull-right'>" + localeTitle.mingXi
			+ "</span>";
			var ele = panels.getCollapsePanelEle(tableId + "Div", title, expand, clickListener);
			ele.append(PanelTablesUtil.getSmileInfo(localeTitle.channel.WeiFaShengShuangTongDaoTongShiZhongDuan));
		}
	}
}
function DefectMan() {
	var util = new DailyUtil();
	var defects = undefined; // 保护缺陷及处理情况
	var divId = 'affectObjDiv';
	var panels = new PanelTablesUtil(divId);
	var divTitle = localeTitle.daily.BaoHuQueXian;
	var popMap = {
			defect : new Map()
	};
	var lonlatMaps = {
			defect : new Map()
	};
	this.show = function() {
		initData();
	};
	this.query = function() {
		clearAll();
		initData();
	};
	this.openPop = function(type, value) {
		// 添加保护缺陷弹窗
		var pop = popMap[type].get(value.stationId);
		if (pop) {
			if (pop.isShow()) {
				pop.remove();
			} else {
				pop.show();
			}
		}
	};
	this.openDialog = function(type, value) {
		if (type == "detail") {
			var url = '/ui/map/dialog/daily/dailyDefect.xhtml';
			util.openDialogWithTimeParamter(url, {
				stationId : value
			});
		}
		if (type == "list") {
			var url = '/ui/map/dialog/daily/dailyDefect.xhtml';
			util.openDialogWithTimeParamter(url);
		}
	};
	function initData() {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		$.getJSON("/rest/protectDefect/getProtectDefect/" + start + "/" + end, function(result) {
			result.sort(sortTime);
			defects = result;
			var res = util.loadMapAndEquip(defects, [ 'lon', 'lat', 'substationName' ], {
				'stationId' : 'substationId'
			}, 'substationName');
			lonlatMaps.defect = res.map;
			show();
		});
	}
	function sortTime(obj1, obj2) {
		if (obj1.startTime < obj2.startTime) {
			return 1;
		} else {
			return -1;
		}
	}
	function show() {
		showDiv();
		weatherLayer.removeAllFeatures();
		util.markPoint(lonlatMaps.defect, util.getGif('defect'), 'defect', 'defect');
		addDefectPops();
	}
	function showDiv() {
		panels = new PanelTablesUtil(divId);
		panels.setTitle("<span>" + divTitle + "  <small style=\"color:#A6A6A6\">" + localeTitle.daily.BaoHuRiBao
				+ "</small></span>");
		panels.setInfo(util.getQueryDiv());
		addDefectDiv(panels);
		panels.show();
		util.setQueryTimePicker();
	}
	function addDefectDiv(panels) {
		var expand = true;
		var tableId = "dailyDefectTable";
		var title = localeTitle.daily.BaoHuQueXianJiChuLi;
		var openList = 'dailyFaultMan.openDialog("defect","list")';
		var sub = "<span class='pull-right' style='color:gray;' onclick='" + openList + "'>" + localeTitle.mingXi
		+ "</span>";
		if (defects.length > 0) {
			panels.setDangerBox();
			var dataset = util.getDataset(defects, [ 'substationName', 'protectType', {
				value : 'protectQuitTime',
				type : 'secondTimeStr'
			} ]);
			title += "<span title='保护缺陷个数' onclick='" + openList + "' class='badge bg-red pull-right'>"
			+ defects.length + "</span>";
			var tablediv = panels.drawCollapseTable(tableId, title + sub, expand);
			var option = util.getTableOption();
			var columns = [ localeTitle.defect.ChangZhanMingCheng, localeTitle.defect.BaoHuMingCheng, localeTitle.defect.BaoHuTuiChuShiJian ];
			var table = new MyTable(tablediv, columns, option);
			table.setDataSet(dataset).show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			panels.setSuccessBox();
			title += sub;
			var ele = panels.getCollapsePanelEle(tableId, title, expand);
			ele.append(PanelTablesUtil.getSmileInfo(localeTitle.defect.WuQueXianJiLu));
		}
	}
	function addDefectPops() {
		var map = new Map();
		for ( var i in defects) {
			var d = defects[i];
			var ds = map.get(d.lon + ',' + d.lat + ',' + d.substationId);
			if (!ds) {
				ds = [];
				map.put(d.lon + ',' + d.lat + ',' + d.substationId, ds);
			}
			ds.push(d);
		}
		popMap.defect.clear();
		map.each(function(index, key, value) {
			var pop = getDefectPop(key, value);
			// pop.show();
			popMap.defect.put(value[0].substationId, pop);
		});
	}
	function getDefectPop(lonlat, ds) {
		lonlat = lonlat.split(",");
		var pop = new Popup(lonlat[0], lonlat[1]);
		var listener = 'dailyFaultMan.openDialog("defect","detail","' + lonlat[2] + '")';
		pop.setTitle(ds[0].substationName).setTitleIconClickListener(listener).setTitleSelfClickListener(listener);
		for ( var i in ds) {
			var d = ds[i];
			pop.setRowContent(d.defectDescription).setRowClickListener(listener);
		}
		return pop;
	}
}
function OverhaulMan() {
	var divId = "affectObjDiv";
	var util = new DailyUtil();
	var currentPop = undefined;
	var overhauls = {
			todo : undefined,
			doing : undefined,
			done : undefined
	};
	var lonlatMaps = {
			todo : new Map(),
			doing : new Map(),
			done : new Map()
	};
	var equipments = {
			todo : [],
			doing : [],
			done : []
	};
	var popMap = {
			todo : new Map(),
			doing : new Map(),
			done : new Map()
	};
	var selectedTypes = {
			todo : false,
			doing : false,
			done : true
	};

	this.show = function() {
		initData();
	};
	this.query = function() {
		clearAll();
		initData();
	};
	this.onPanelClick = function(type) {
		selectedTypes[type] = !selectedTypes[type];
		showPoints();
	};
	function showPoints() {
		selectedLayer.removeAllFeatures();
		weatherLayer.removeAllFeatures();
		map.removeAllPopup();
		for ( var item in selectedTypes) {
			if (selectedTypes[item]) {
				util.markPoint(lonlatMaps[item], "/resources/img/daily/" + item + ".gif", 'overhaul', item);
				util.markLines(equipments[item]);
				$('#' + item + 'StatusIcon').addClass("text-red");
			} else {
				$('#' + item + 'StatusIcon').removeClass("text-red");
			}
		}
	}
	this.openDialog = function(type, value) {
		var url = "/ui/map/dialog/daily/dailyOverhaul.xhtml";
		if (type == "detail") {
			util.openDialogWithTimeParamter(url, {
				stationId : value
			});
		}
		if (type == "list") {
			util.openDialogWithTimeParamter(url);
		}
	};
	this.openPop = function(type, value) {
		var pop = popMap[type].get(value.stationIdOrAreaValue);
		if (pop.isShow()) {
			pop.remove();
			currentPop = undefined;
		} else {
			if (currentPop) {
				currentPop.remove();
			}
			pop.show();
			currentPop = pop;
		}
	};
	function initData() {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		$.getJSON("/rest/protectOverhaul/getMapProtectOverhaul/"+start+"/"+end, function(result) {
			overhauls.todo = result.todo;
			overhauls.doing = result.doing;
			overhauls.done = result.done;
			for ( var i in overhauls) {
				var res = util.loadMapAndEquip(overhauls[i], [ 'lon', 'lat', 'station_name' ], {
					stationIdOrAreaValue : 'station_id'
				}, 'station_name');
				lonlatMaps[i] = res.map;
				equipments[i] = res.equipment;
			}
			show();
		});
	}
	function show() {
		showDiv();
		showPoints();
	}
	function showDiv() {
		var panel = new PanelTablesUtil(divId);
		panel.setTitle("<span>" + localeTitle.daily.BaoHuJianXiu + "  <small style=\"color:#A6A6A6\">"
				+ localeTitle.daily.BaoHuRiBao + "</small></span>");
		panel.setInfo(util.getQueryDiv());
		if ((!overhauls.todo || overhauls.todo.length == 0 )
				&& (!overhauls.doing || overhauls.doing.length == 0) 
				&& (!overhauls.done || overhauls.done.length == 0)) {
			panel.setSuccessBox();
			panel.setInfo(PanelTablesUtil.getSmileInfo("无检修计划"));
		} else {
			panel.setDangerBox();
			addPanelInfo(panel);
			addOverhaulPops('todo');
			addOverhaulPops('doing');
			addOverhaulPops('done');
		}
		panel.show();
		util.setQueryTimePicker();
	}
	function addPanelInfo(panel) {
		var info = $('<table class="table table-hover" style="width:100%"></table>');
		info.append(getImage('overhaul', '全部', 'brown'));
		info.append(getImage('done', '已完工', 'green'));
		info.append(getImage('doing', '进行中', 'blue'));
		info.append(getImage('todo', '待开工', 'orange'));
		panel.setInfo(info);
		function getEnglishName(name) {
			var engName = "";
			if (name == '全部') {
				engName = localeTitle.daily.QuanBu;
			} else if (name == '已完工') {
				engName = localeTitle.daily.YiWanGong;
			} else if (name == '进行中') {
				engName = localeTitle.daily.JinXingZhong;
			} else if (name == '待开工') {
				engName = localeTitle.daily.DaiKaiGong;
			}
			return engName;
		}
		function getImage(type, name, color) {
			var listener = 'dailyFaultMan.onPanelClick(\'' + type + '\')';
			if (name == '全部') {
				listener = "dailyFaultMan.openDialog('overhaul','list')";
			}
			var div = '<div style="cursor:pointer;" onclick="' + listener + '">';
			var img = '<img src="/resources/img/daily/' + type + '.gif" style="width:30px;height:30px;" alt="' + name
			+ '"> <img>';
			var item = '<span>' + getEnglishName(name) + '</span>';
			if (name == '待开工') {
				var now = new Date();
				item = '<span>' + localeTitle.daily.JieZhi + '<span style="font-size:18px;">'
				+ util.getDayTimeStr(now.getTime()) + '</span>,' + localeTitle.daily.DaiKaiGong + '<span>';
			}
			var num = '';
			var map = '';
			if (name == '全部') {
				var length = 0;
				for ( var i in overhauls) {
					if (overhauls[i]) {
						length += overhauls[i].length;
					}
				}
				num = '<span style="margin:5px;font-size:25px;color:' + color + ';">' + length + '</span>';
				map = '<span class="pull-right" style="margin-right:20px;color:gray;">' + localeTitle.mingXi
				+ '</span>';
			} else {
				num = '<span style="margin:5px;font-size:25px;color:' + color + ';">' + overhauls[type].length
				+ '</span>';
				map = '<span class="pull-right" style="margin-right:20px;"><i id="' + type
				+ 'StatusIcon" class="fa fa-map-marker"></i></span>';
			}
			return '<tr><td>' + div + img + item + num + map + '</div></td></tr>';
		}
	}
	function addTodoDiv(panel) {
		var expand = currentType == 'todo';
		var clickListener = 'dailyFaultMan.onPanelClick(\'todo\');';
		var tableId = 'dailyTodoTable';
		var title = localeTitle.daily.DaiKaiGong;
		if (overhauls.todo.length > 0) {
			var dataset = util.getDataset(overhauls.todo, [ 'station_name', 'content' ]);
			title += '<span class="badge bg-yellow pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
			panel.drawCollapseTable(tableId, title, expand, clickListener);
			var option = util.getTableOption();
			option.columnDefs = [ {
				targets : 0,
				width : '33%'
			}, {
				targets : 1,
				width : '67%'
			} ];
			var columns = [ '检修地点', '检修内容' ];
			var table = new MyTable(tableId, columns, option);
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			panel.getCollapsePanelEle(tableId + 'parent', title, expand, clickListener).append(
					PanelTablesUtil.getSmileInfo("无" + title + "计划"));
		}
	}
	function addDoingDiv(panel) {
		var expand = currentType == 'doing';
		var clickListener = 'dailyFaultMan.onPanelClick(\'doing\');';
		var tableId = 'dailyDoingTable';
		var title = localeTitle.daily.JinXingZhong;
		if (overhauls.doing.length > 0) {
			var dataset = util.getDataset(overhauls.doing, [ 'station_name', 'content' ]);
			title += '<span class="badge bg-blue pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
			panel.drawCollapseTable(tableId, title, expand, clickListener);
			var option = util.getTableOption();
			option.columnDefs = [ {
				targets : 0,
				width : '33%'
			}, {
				targets : 1,
				width : '67%'
			} ];
			var columns = [ '检修地点', '检修内容' ];
			var table = new MyTable(tableId, columns, option);
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			panel.getCollapsePanelEle(tableId + 'parent', title, expand, clickListener).append(
					PanelTablesUtil.getSmileInfo("无" + title + "计划"));
		}
	}
	function addDoneDiv(panel) {
		var expand = currentType == 'done';
		var clickListener = 'dailyFaultMan.onPanelClick(\'done\');';
		var tableId = 'dailyDoneTable';
		var title = localeTitle.daily.YiWanGong;
		var sub = '<span style="color:gray;" class="pull-right">昨日</span>';
		if (overhauls.done.length > 0) {
			var dataset = util.getDataset(overhauls.done, [ 'station_name', 'content' ]);
			title += '<span class="badge bg-green pull-right" title="' + title + '计划数">' + dataset.length + '</span>';
			title += sub;
			panel.drawCollapseTable(tableId, title, expand, clickListener);
			var option = util.getTableOption();
			option.columnDefs = [ {
				targets : 0,
				width : '33%'
			}, {
				targets : 1,
				width : '67%'
			} ];
			var columns = [ '检修地点', '检修内容' ];
			var table = new MyTable(tableId, columns, option);
			table.setDataSet(dataset);
			table.show();
			table.onRowClick(function(data) {
				if (data) {
					$("#input_search").val(data[0]);
					searchObj(true);
				}
			});
		} else {
			panel.getCollapsePanelEle(tableId + 'parent', title + sub, expand, clickListener).append(
					PanelTablesUtil.getSmileInfo("无" + title + "计划"));
		}
	}
	function addOverhaulPops(type) {
		var lonlats = new Map();
		for ( var i in overhauls[type]) {
			var v = overhauls[type][i];
			if (v.lon && v.lat) {
				var fs = lonlats.get(v.lon + ',' + v.lat);
				if (!fs) {
					fs = [];
					lonlats.put(v.lon + ',' + v.lat, fs);
				}
				fs.push(v);
			}
		}
		popMap[type].clear();
		lonlats.each(function(index, key, value) {
			var pop = undefined;
			switch (type) {
			case 'todo':
				pop = getTodoPop(value);
				break;
			case 'doing':
				pop = getDoingPop(value);
				break;
			case 'done':
				pop = getDonePop(value);
				break;
			}
			popMap[type].put(value[0]['station_id'], pop);
			// pop.show();
		});
	}
	function getTodoPop(value) {
		var pop = new Popup(value[0].lon, value[0].lat);
		var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
		pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
				clickListener);
		for ( var i in value) {
			pop.setRowContent(value[i].content).setRowClickListener(clickListener);
		}
		pop.setAutoSize(true);
		pop.showCloseIcon(true);
		return pop;
	}
	function getDoingPop(value) {
		var pop = new Popup(value[0].lon, value[0].lat);
		var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
		pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
				clickListener);
		for ( var i in value) {
			pop.setRowContent(value[i].content).setRowClickListener(clickListener);
		}
		pop.setAutoSize(true);
		pop.showCloseIcon(true);
		return pop;
	}
	function getDonePop(value) {
		var pop = new Popup(value[0].lon, value[0].lat);
		var clickListener = 'dailyFaultMan.openDialog("overhaul","detail","' + value[0]['station_id'] + '");';
		pop.setTitle(value[0]['station_name']).setTitleIconClickListener(clickListener).setTitleSelfClickListener(
				clickListener);
		for ( var i in value) {
			pop.setRowContent(value[i].content).setRowClickListener(clickListener);
		}
		pop.setAutoSize(true);
		pop.showCloseIcon(true);
		return pop;
	}
	function drawBar() {
		bar3DLayer.removeAllFeatures();
		weatherLayer.removeAllFeatures();
		bar3DLayer.setVisibility(true);
		bar3DLayer.div.style.zIndex = 400;
		var features = [];
		var labelFeas = [];
		var max = 5;
		exceedMap.each(function(index, key, value) {
			max = value.length > max ? value.length : max;
		});
		bar3DLayer.chartsSetting.codomain[1] = max;
		for ( var i in geos) {
			var details = [];
			exceedMap.each(function(index, key, value) {
				if (key.indexOf(geos[i][0]) > -1) {
					details = value;
				}
			});
			var geo = new SuperMap.Geometry.Point(geos[i][1], geos[i][2]);
			var attrs = {
					NAME : geos[i][0],
					NUM : details.length,
					TYPE : 'overhaul'
			};
			var fea = new SuperMap.Feature.Vector(geo, attrs);
			features.push(fea);
			labelFeas.push(markNameLabel(geo, geos[i][0]));
			labelFeas.push(markValueLabel(geo, details.length, max));
		}
		bar3DLayer.addFeatures(features);
		weatherLayer.addFeatures(labelFeas);
		weatherLayer.setVisibility(true);
	}
	function markValueLabel(geo, value, max) {
		var maxh = bar3DLayer.chartsSetting.height;
		var h = value * maxh / max;
		var style = {
				fill : 'red',
				label : value + "",
				labelXOffset : -5,
				labelYOffset : h + 15,
				fontColor : "red",
				fontOpacity : "0.8",
				fontSize : "2em",
				fontWeight : "bold",
				fontStyle : "italic"
		};
		var pointFeature = new SuperMap.Feature.Vector(geo, null, style);
		return pointFeature;
	}
	function markNameLabel(geo, name) {
		// 画一个label
		var style = {
				label : name,
				labelXOffset : -10,
				labelYOffset : -20,
				fontColor : "black",
				fontOpacity : "0.5",
				fontFamily : "隶书",
				fontSize : "3em",
				fontWeight : "bold",
				fontStyle : "italic"
		};
		var pointFeature = new SuperMap.Feature.Vector(geo, null, style);
		return pointFeature;
	}
}
function RiskMan() {
	var util = new DailyUtil();
	this.show = function() {
		var url = '/ui/map/dialog/daily/dailyRiskDetail.xhtml';
		util.openDialogWithTimeParamter(url);
	};
}
function NewEquipmentMan() {
	var util = new DailyUtil();
	this.show = function() {
		var url = '/ui/map/dialog/daily/dailyNewEquipment.xhtml';
		util.openDialogWithTimeParamter(url);
	};
}
function SpecialReportMan() {
	var util = new DailyUtil();
	this.show = function() {
		var url = '/ui/map/dialog/daily/dailySpeicalReport.xhtml';
		util.openDialogWithTimeParamter(url);
	};
}
function HistoryFaultFeedBackMan() {
	var util = new DailyUtil();
	this.show = function() {
		var url = '/ui/map/dialog/daily/dailyHistoryFaultFeedback.xhtml';
		util.openDialogWithTimeParamter(url);
	};
}
function DailyUtil() {
	var divId = 'affectObjDiv';
	this.markPoint = function(map, gif, group, type) {
		markPoint(map, gif, group, type);
	};
	function markPoint(map, gif, group, type) {
		var gwidth = 35;
		var gheight = 35;
		// map的key 'lon+","+lat+","+name' value [id,...]
		var heatPoints = [];
		map.each(function(index, key, value) {
			var lonlatName = key.split(',');
			var point = new SuperMap.Geometry.Point(lonlatName[0], lonlatName[1]);
			var gifPoint = new SuperMap.Feature.Vector(point, null, {
				externalGraphic : gif,
				graphicWidth : gwidth,
				graphicHeight : gheight,
				graphicOpacity : 1,
			});
			gifPoint.data.type = "daily";
			gifPoint.data.group = group;
			gifPoint.data.groupType = type;
			gifPoint.data.value = value;
			heatPoints.push(gifPoint);
		});
		weatherLayer.addFeatures(heatPoints);
		weatherLayer.setVisibility(true);
		selectFeature.activate();
	}
	this.markLines = function(equipments) {
		markLines(equipments);
	};
	function markLines(equipments) {
		for ( var j in equipments) {
			for (var i = 0; i < lines500.length; i++) {
				var obj = lines500[i];
				if (equipments[j] && obj.lineName.indexOf(equipments[j]) > -1) {
					draw_acline_one(lines500[i]);
				}
			}
		}
	}
	this.getQueryDiv = function() {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		var queryDiv = $('<div id="queryDiv" style="display:block"/>');
		queryDiv
		.html(
				'<div class="btn-group">'
				+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-1)">'+localeTitle.ZuoTian+'</button>'
				+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-3)">'+localeTitle.QianSanTian+'</button>'
				+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-4)">'+localeTitle.QianSiTian+'</button>'
				+ '<button class="btn btn-sm btn-flat btn-default" onclick="dailyFaultMan.changeDate(0,-8)">'+localeTitle.QianBaTian+'</button>'
				+ '</div>'
				+ '<div style="display:flex;">'
				+ '<button class="btn btn-flat btn-default" onclick="dailyFaultMan.dateMinus()"><i class="fa fa-arrow-left"></i></button>'
				+ '<input type="text" class="form-control" id="start" value="'
				+ start
				+ '" />'
				+ '<input type="text" class="form-control" id="end" value="'
				+ end
				+ '" />'
				+ '<button class="btn btn-flat btn-default" onclick="dailyFaultMan.query();">' + localeTitle.search
				+ '</button>' + '</div>'
				+ '<div id="dailyQueryError" class="collapse" style="color:red"></div>');
		return queryDiv;
	};
	this.setQueryTimePicker = function() {
		setTimePicker();
	};
	function setTimePicker() {
		var e = new Date();
		$('#start').datetimepicker({
			format : 'yyyy-mm-dd',
			minView : 2,
			autoclose : true,
			endDate : e,
			todayHighlight : true
		});
		$('#end').datetimepicker({
			format : 'yyyy-mm-dd',
			minView : 2,
			autoclose : true,
			endDate : e,
			pickerPosition : 'bottom-left',
			todayHighlight : true
		});
	}
	function appendQueryDiv(parent) {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		var queryDiv = $('<div id="queryDiv" style="display:block"/>');
		queryDiv
		.html('<div class="input-group">'
				+ '<div class="input-group-btn">'
				+ '<button class="btn btn-default" onclick="dailyFaultMan.dateMinus()"><i class="fa fa-arrow-left"></i></button>'
				+ '</div>'
				+ '<input type="text" style="width:107px" class="form-control" id="start" value="'
				+ start
				+ '" />'
				+ '<input type="text" style="width:107px"  class="form-control" id="end" value="'
				+ end
				+ '" />'
				+ '<div class="input-group-btn">'
				+ '<button class="btn btn-default" onclick="dailyFaultMan.query();">' + localeTitle.search
				+ '</button>' + '</div>' + '</div>');
		parent.append(queryDiv);
		var e = new Date();
		e.setDate(e.getDate() - 1);
		$('#start').datetimepicker({
			format : 'yyyy-mm-dd',
			minView : 2,
			autoclose : true,
			endDate : e,
			todayHighlight : true
		});
		$('#end').datetimepicker({
			format : 'yyyy-mm-dd',
			minView : 2,
			autoclose : true,
			endDate : e,
			pickerPosition : 'bottom-left',
			todayHighlight : true
		});
		return queryDiv;
	}
	;
	this.getTableOption = function() {
		var opt = MyTable.getDefaultOptions();
		opt.scrollX = false;
		opt.autoWidth = false;
		opt.columnDefs = [ {
			"width" : "33%",
			"targets" : 0
		}, {
			"width" : "33%",
			"targets" : 1
		}, {
			"width" : "33%",
			"targets" : 2
		} ];
		opt.scrollY = 230;
		opt.scrollCollapse = true;
		return opt;
	};
	this.getFaultTableOption = function() {
		var opt = MyTable.getDefaultOptions();
		opt.scrollX = false;
		opt.autoWidth = false;
		opt.columnDefs = [ {
			"width" : "33%",
			"targets" : 0
		}, {
			"width" : "33%",
			"targets" : 1
		}, {
			"width" : "33%",
			"targets" : 2
		},{
			"targets" : 3,
			"visible":false
		} ];
		opt.scrollY = 230;
		opt.scrollCollapse = true;
		return opt;
	};
	this.commonPanelTable = function(parendId, titleName, columns, searchIndex, dataset, expand, clickListener, type,
			subTitle, subTitleClick) {
		var tbid = 'daily' + type + 'Table';
		var div = drawTablePanel(parendId, titleName, tbid, expand, clickListener, subTitle, subTitleClick);
		div.append('<table id=' + tbid + ' class="table table-hover"></table>');
		var myOpt = MyTable.getDefaultOptions();
		myOpt.scrollX = false;
		myOpt.autoWidth = false;
		myOpt.columnDefs = [ {
			"width" : "33%",
			"targets" : 0
		}, {
			"width" : "33%",
			"targets" : 1
		}, {
			"width" : "33%",
			"targets" : 2
		} ];
		myOpt.scrollY = 230;
		myOpt.scrollCollapse = true;
		var tab = new MyTable(tbid, columns, myOpt);
		tab.setDataSet(dataset);
		tab.show();
		tab.onRowClick(function(data) {
			if (data) {
				$("#input_search").val(data[searchIndex]);
				searchObj(true);
			}
		});
		/*
		 * tab.onRowDbClick(function(data){ if(data){
		 * MyModal.showModal(urls[type]+data[3],1000,550); } });
		 */
		return div;
	};
	this.commonNoData = function(parentDivId, infoDivId, title, info, expand, clickListener, subTitle, subTitleClick) {
		var div = drawTablePanel(parentDivId, title, infoDivId, expand, clickListener, subTitle, subTitleClick);
		div.append('<p class="text-success">' + info + '</p>');
		div.css('text-align', 'center');
		return div;
	};
	function drawTablePanel(parentDivId, title, tableId, expand, clickListener, subTitle, subTitleClick) {
		var collIn = "";
		if (expand) {
			collIn = " in ";
		}
		var sub = "";
		if (subTitle) {
			sub = '<span class="pull-right" onClick="'
				+ subTitleClick
				+ '" onMouseOver="this.style.textDecoration=\'underline\';this.style.cursor=\'pointer\';"'
				+ 'onMouseOut="this.style.textDecoration=\'none\';this.style.cursor=\'none\';"><small style="color:#A6A6A6" >'
				+ subTitle + '</small></span>';
		}
		var h = $('<div class="panel panel-default" style="margin:0">' + '<ul class="nav nav-pills nav-stacked">'
				+ '<li class="panel-title">' + '<a onclick=' + clickListener + ' data-parent="#' + parentDivId
				+ '" data-toggle="collapse" href="#' + tableId + 'Parent">' + title + sub + '</a>' + '</li>' + '</ul>'
				+ '</div>');
		var tabdiv = $('<div id="' + tableId + 'Parent" class="panel-collapse collapse ' + collIn + '">' + '</div>');
		$('#' + parentDivId).append(h);
		h.append(tabdiv);
		return tabdiv;
	}
	this.addNoInfo = function(text, div, clickListener) {
		$('#' + div).append(
				'<div onclick=' + clickListener + ' class="panel panel-default" style="margin:0;height:100px;">'
				+ '<div class="col-md-12" style="text-align:center;padding-top:20px;">'
				+ '<i class="fa fa-smile-o"  style="font-size:40px !important;color:green"></i>'
				+ '<p class="text-success">' + text + '</p>' + '</div>' + '</div>');
	};
	this.setSuccessBox = function() {
		var div = $('#' + divId);
		if (div.hasClass('box-danger')) {
			div.removeClass('box-danger');
			div.addClass('box-success');
		}
	};
	this.setDangerBox = function() {
		var div = $('#' + divId);
		if (div.hasClass('box-success')) {
			div.removeClass('box-success');
			div.addClass('box-danger');
		}
	};
	this.getNormalTimeStr = function(millis) {
		getNormalTimeStr(millis);
	};
	function getNormalTimeStr(millis) {
		if (!millis) {
			return "";
		}
		var s = "";
		var t = new Date(millis);
		var today = new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		var todayMillis = today.getTime();
		var oneDayMillis = 24 * 60 * 60 * 1000;
		if (millis >= todayMillis && millis < todayMillis + oneDayMillis) {
			s += "今天";
		} else if (millis >= todayMillis - oneDayMillis && millis < todayMillis) {
			s += "昨天";
		} else if (millis >= todayMillis - 2 * oneDayMillis && millis < todayMillis - oneDayMillis) {
			s += "前天";
		} else {
			s += getDayTimeStr(millis);
		}
		var h = t.getHours() > 9 ? t.getHours() : "0" + t.getHours();
		var min = t.getMinutes() > 9 ? t.getMinutes() : "0" + t.getMinutes();
		var sec = t.getSeconds() > 9 ? t.getSeconds() : "0" + t.getSeconds();
		s += " " + h + ":" + min + ":" + sec;
		return s;
	}
	this.getSecondTimeStr = function(millis) {
		return getSecondTimeStr(millis);
	};
	function getSecondTimeStr(millis) {
		if (!millis) {
			return "";
		}
		var t = new Date(millis);

		var m = t.getMonth() + 1 > 9 ? (t.getMonth() + 1) : ("0" + (t.getMonth() + 1));
		var d = t.getDate() > 9 ? t.getDate() : "0" +t.getDate();
		var h = t.getHours() > 9 ? t.getHours() : "0" +t.getHours();
		var min = t.getMinutes() > 9 ? t.getMinutes() : "0" +t.getMinutes();
		var s = t.getSeconds() > 9 ? t.getSeconds() : "0" +t.getSeconds();
		var timestr = t.getFullYear() + "-" + m + "-" + d + " " +h + ":" + min + ":" + s;

		return timestr;
	}
	this.getDayTimeStr = function(millis) {
		return getDayTimeStr(millis);
	};
	/**
	 * 时间戳获取时间
	 */
	function getDayTimeStr(millis) {
		if (!millis) {
			return "";
		}
		var t = new Date(millis);
		var m = t.getMonth() + 1 > 9 ? (t.getMonth() + 1) : ("0" + (t.getMonth() + 1));
		var d = t.getDate() > 9 ? t.getDate() : "0" + t.getDate();
// var h = t.getHours()> 9 ? t.getHours() : "0" + t.getHours();
// var mi = t.getMinutes()> 9 ? t.getMinutes() : "0" + t.getMinutes();
// var s = t.getSeconds()> 9 ? t.getSeconds() : "0" + t.getSeconds();
// yyyy-MM-dd hh:mm:ss
// var timestr = t.getFullYear() + "-" + m + "-" + d + " " + h +":"+ mi+":"+s;
 var timestr = t.getFullYear() + "-" + m + "-" + d;
		return timestr;
	}
	this.loadMapAndEquip = function(data, keyIndexArr, valueIndexObj, equipIndex) {
		// 若 keyIndexArr:[1,2] valueIndex:3 equipIndex 4
		// map组织成 key "data[i][1]+','+data[i][2]" value [data[i][3],...]
		// equipment 组织成 [data[i][4],...]
		var map = new Map();
		var equip = [];
		for ( var i in data) {
			equip.push(data[i][equipIndex]);
			var key = "";
			for ( var j in keyIndexArr) {
				key += data[i][keyIndexArr[j]] + ",";
			}
			key = key.substring(0, key.length - 1);
			var value = {};
			for ( var j in valueIndexObj) {
				value[j] = data[i][valueIndexObj[j]];
			}
			map.put(key, value);
		}
		return {
			map : map,
			equipment : equip
		};
	};
	this.getDataset = function(data, indexArr) {
		var dataset = [];
		for ( var i in data) {
			var d = [];
			for ( var j in indexArr) {
				var index = indexArr[j];
				var v = data[i][index.value ? index.value : index];
				if (v) {
					switch (index.type) {
					case 'dayTimeStr':
						d.push(getDayTimeStr(v.time ? v.time : v));
						break;
					case 'secondTimeStr':
						d.push(getSecondTimeStr(v.time ? v.time : v));
						break;
					default:
						d.push(v);
					}
				} else {
					d.push('');
				}
			}
			dataset.push(d);
		}
		return dataset;
	};
	this.openDialogWithTimeParamter = function(url, value) {
		var start = dailyFaultMan.getStart();
		var end = dailyFaultMan.getEnd();
		var params = '?startTime=' + start + '&endTime=' + end;
		if (value) {
			for ( var i in value) {
				params += "&" + i + "=" + value[i];
			}
		}
		if (url && url != "") {
			MyModal.showModal(url + params);
		}
	};
	this.openDialog = function(url, value) {
		if (url && url != "") {
			var params = '';
			if (value) {
				params += "?";
				for ( var i in value) {
					params += i + "=" + value[i] + "&";
				}
				params = params.substring(0, params.length - 1);
			}
			MyModal.showModal(url + params);
		}
	};
	this.getGif = function(type) {
		return '/resources/img/daily/' + type + '.gif';
	};
}
/**
 * 该方法主要用于将距离较近的多个点的数据，汇集到同一个点上。这个点是符合条件这些点中的第一个点。 默认判断数据的字段名：lon和lat 可用方法：
 * setData(data);//data的格式为集合 [{lon:12,lat:13,...},{}]
 * setLonlatProperty(lon,lat);//设置属性名，用于去数据中寻找经纬度。默认 “lon” 和 “lat”
 * isChange(level);//检查本缩放等级和上一个传入的等级，融合范围是否一样大（一样大考虑不重新渲染页面）。上一次的范围在setData时会被重置。
 * getMergeData(level);//返回得到融合后的数据。level为当前页面的缩放等级。 返回数据格式：
 * [{range:[minlon,maxlon,minlat,maxlat],data:[....]},{}]
 * @returns
 */
function MergeGeo(){

	var data = [];

	var lonProperty = "lon";
	var latProperty = "lat";
	
	var lastRange = undefined;
	
	this.setLonlatProperty = function(lon,lat){
		lonProperty = lon;
		latProperty = lat;
	};
	
	this.setData = function(d){
		lastRange = undefined;
		data = d;
	};
	this.getMergeData = function(level){
		return merge(level);
	};
	this.isChange = function(level){
		if(!lastRange){
			return true;
		}
		var range = getLonLatRange(level);
		if(range[0]>lastRange[0] || range[0]<lastRange[0]
			|| range[1] > lastRange[1] || range[1] <lastRange[1]){
			return true;
		}else{
			return false;
		}
	};
	// 合并
	function merge(level){
		var range = getLonLatRange(level);
		lastRange = range;
		var group = [];// {center:[],data:[]}
		for(var i in data){
			var d = data[i];
			var lon = Number(d[lonProperty]);
			var lat = Number(d[latProperty]);
			if(!lon || !lat){
				console.log( "id为"+data[i].id +"的数据经纬度不可用");
				continue;
			}
			var success = false;
			for(var j in group){// [[lon],[],[]]
				var g = group[j];
				if(inRange(lon,lat,g.range)){
					g.data.push(d);
					success = true;
				}
			}
			if(!success){
				group.push({
					range:[lon+range[0],lon-range[0],lat+range[1],lat-range[1]],
					data:[d]
				});
			}
		}
		return group;
	}
	function inRange(lon,lat,range){
		if(lon <= range[0] && lon >= range[1] && lat <= range[2] && lat >= range[3]){
			return true;
		}
		return false;
	}
	// currentZoomLevel
	function getLonLatRange(level){
		var lonlat = [];
		switch(level){
		case 5:
		case 6:
		case 7: 
		case 8:          
		case 9:
		case 10:lonlat = [0.5,0.5];break; // 7-10，小于50km合并。初始化的时候的level
		case 11:
		case 12: 
		case 13:lonlat = [0.05,0.05];break;// 11-13，小于5千米的会合并
		case 14:
		case 15:
		case 16:
		case 17: 
		default:lonlat = [0,0];break;	// 彻底分开
		}
		return lonlat;
	}
}
